
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;
import java.sql.*;

final class Item extends javax.swing.JInternalFrame {

    PreparedStatement statement;
    Systems systems=new Systems();
    Thread processThread=new Thread();
    Thread titleThread=new Thread();

    /** Creates new form TransactionType */
     Item()
    {
        initComponents();
        /* Execute submit thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            resetCombo();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jAddressLabel = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLocationComboBox = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jDescriptionTextArea = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jNameTextField = new javax.swing.JTextField();
        jPriceTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jCategoryComboBox = new javax.swing.JComboBox();
        jTypeComboBox = new javax.swing.JComboBox();
        jStockUnitComboBox = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jTaxTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();

        setClosable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(Item.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameIconified(evt);
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jAddressLabel.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jAddressLabel.setText(resourceMap.getString("jAddressLabel.text")); // NOI18N
        jAddressLabel.setName("jAddressLabel"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLocationComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jLocationComboBox.setName("jLocationComboBox"); // NOI18N
        jLocationComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jLocationComboBoxActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jDescriptionTextArea.setColumns(20);
        jDescriptionTextArea.setLineWrap(true);
        jDescriptionTextArea.setRows(5);
        jDescriptionTextArea.setName("jDescriptionTextArea"); // NOI18N
        jDescriptionTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jDescriptionTextAreaKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jDescriptionTextArea);

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jNameTextField.setText(resourceMap.getString("jNameTextField.text")); // NOI18N
        jNameTextField.setName("jNameTextField"); // NOI18N
        jNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jNameTextFieldActionPerformed(evt);
            }
        });
        jNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jNameTextFieldKeyTyped(evt);
            }
        });

        jPriceTextField.setText(resourceMap.getString("jPriceTextField.text")); // NOI18N
        jPriceTextField.setName("jPriceTextField"); // NOI18N
        jPriceTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jPriceTextFieldKeyTyped(evt);
            }
        });

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jCategoryComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jCategoryComboBox.setName("jCategoryComboBox"); // NOI18N
        jCategoryComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCategoryComboBoxActionPerformed(evt);
            }
        });

        jTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Stock", "Non-Stock", "Credit Charges", "Debit Charges" }));
        jTypeComboBox.setName("jTypeComboBox"); // NOI18N
        jTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTypeComboBoxActionPerformed(evt);
            }
        });

        jStockUnitComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --" }));
        jStockUnitComboBox.setEnabled(false);
        jStockUnitComboBox.setName("jStockUnitComboBox"); // NOI18N
        jStockUnitComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jStockUnitComboBoxActionPerformed(evt);
            }
        });

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jTaxTextField.setName("jTaxTextField"); // NOI18N
        jTaxTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTaxTextFieldKeyTyped(evt);
            }
        });

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jAddressLabel)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4))
                                .addGap(28, 28, 28)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jPriceTextField)
                                    .addComponent(jNameTextField)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel5)))
                .addGap(48, 48, 48)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jCategoryComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLocationComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTypeComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, 87, Short.MAX_VALUE)
                            .addComponent(jStockUnitComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTaxTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(jAddressLabel))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jPriceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jCategoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLocationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jStockUnitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTaxTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNameTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jNameTextFieldActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        String value=jPriceTextField.getText();
        
        if(jNameTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Name ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jPriceTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Price ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jDescriptionTextArea.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Item's Description ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!systems.isStringDecimal(value))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Price Must Be in Money Format ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(!systems.isStringDecimal(jTaxTextField.getText()))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Tax Must Be in Money Format ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jTypeComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Item's Type ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jCategoryComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Item's Category ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jStockUnitComboBox.isEnabled()&&jStockUnitComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Item's Stock Unit ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        String itemName=systems.getValue(OpenMSApp.Database_A, "Select * from item where vName='"+jNameTextField.getText().trim()+"'", 1);

        if(!itemName.isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Item name already exists ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return; 
        }
       
        else
        {
            /* Execute submit thread */
            processThread=new Thread(new Runnable() {
                public void run() {
                disableControls();
                submitData();
                reset();
                }
            });
            titleThread=new Thread(new Runnable() {
                public void run() {
                    while(processThread.isAlive())setProcessingTitle(titleThread);
                    enableControls();
                    System.out.println("itemThread stopped runing.");
                }
            });
            processThread.start();
            titleThread.start();
        }
        //JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Bank Registered Successfully ","Execution SUCCESSFUL !",JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. New Item - Processing Request");
            thread.sleep(500);
            this.setTitle("::. New Item - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. New Item - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. New Item - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        if(processThread.isAlive())
        {
            try{
                processThread.stop();
                titleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. New Item");
            enableControls();
        }
        else
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jNameTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jNameTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jNameTextField.getText();
        if(value.length()>49)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (50) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
            String newValue=String.copyValueOf(value.toCharArray(),0, 49);
            jNameTextField.setText(newValue);
        }
    }//GEN-LAST:event_jNameTextFieldKeyTyped

    private void jDescriptionTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jDescriptionTextAreaKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jDescriptionTextAreaKeyTyped

    private void jPriceTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPriceTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jPriceTextField.getText();
        if(!systems.isStringDecimal(value))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Value entered is not in money format \n           Please Modify !","ERROR !",JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_jPriceTextFieldKeyTyped

    private void formInternalFrameIconified(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameIconified
        // TODO add your handling code here:
        System.out.println("New Location InterFrameIconified");
    }//GEN-LAST:event_formInternalFrameIconified

    private void jStockUnitComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jStockUnitComboBoxActionPerformed
        // TODO add your handling code here:
        if(jStockUnitComboBox.getSelectedItem().equals("-- Select --"))
        {
            resetStockUnit();
        }
    }//GEN-LAST:event_jStockUnitComboBoxActionPerformed

    private void jTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTypeComboBoxActionPerformed
        // TODO add your handling code here
        if(jTypeComboBox.getSelectedItem().toString().trim().equals("Stock"))
        {
            jStockUnitComboBox.setEnabled(true);
            resetStockUnit();
        }
        else
        {
            jStockUnitComboBox.setEnabled(false);
        }
    }//GEN-LAST:event_jTypeComboBoxActionPerformed

    private void jCategoryComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCategoryComboBoxActionPerformed
        // TODO add your handling code here:
        if(jCategoryComboBox.getSelectedItem().equals("-- Select --"))
        {
            resetItemCategory();
        }
    }//GEN-LAST:event_jCategoryComboBoxActionPerformed

    private void jLocationComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLocationComboBoxActionPerformed
        // TODO add your handling code here:
        if(jLocationComboBox.getSelectedItem().equals("-- Select --"))
        {
            resetItemLocation();
        }
    }//GEN-LAST:event_jLocationComboBoxActionPerformed

private void jTaxTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTaxTextFieldKeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_jTaxTextFieldKeyTyped

     String getItemLocation()
    {
        String location=String.valueOf(jLocationComboBox.getSelectedItem());

        if(location.equals("-- Select --"))
        {
            location="";
        }
        return location;
    }
     String getItemStockUnit()
    {
        String stockUnit=String.valueOf(jStockUnitComboBox.getSelectedItem());

        if(stockUnit.equals("-- Select --"))
        {
            stockUnit="";
        }
        return stockUnit;
    }
     void resetItemLocation()
    {
        String[] location=systems.getTableDataArray(OpenMSApp.Database_A,"ItemLocation",2);
        location[0]="-- Select --";

        jLocationComboBox.setModel(new DefaultComboBoxModel(location));
        jLocationComboBox.setSelectedItem("-- Select --");
    }
     void resetItemCategory()
    {
        String[] category=systems.getTableDataArray(OpenMSApp.Database_A,"ItemCategory",2);
        category[0]="-- Select --";

        jCategoryComboBox.setModel(new DefaultComboBoxModel(category));
        jCategoryComboBox.setSelectedItem("-- Select --");
    }
     void resetStockUnit()
    {
        String[] stockUnit=systems.getTableDataArray(OpenMSApp.Database_A,"ItemUnit",2);
        stockUnit[0]="-- Select --";

        jStockUnitComboBox.setModel(new DefaultComboBoxModel(stockUnit));
        jStockUnitComboBox.setSelectedItem("-- Select --");
    }
     void submitData()
    {
        //Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+" prnInsItem"+Connect.procInitStart+"?,?,?,?,?,?,?,?"+Connect.procInitEnd);
            try
            {
                statement.setString(1,jNameTextField.getText().trim());
                statement.setString(2,jDescriptionTextArea.getText().trim());
                statement.setString(3,String.valueOf(jTypeComboBox.getSelectedItem()));
                statement.setString(4,String.valueOf(jCategoryComboBox.getSelectedItem()));
                statement.setString(5,getItemLocation());
                statement.setString(6,systems.converToRealMoneyFormat(jPriceTextField.getText().trim()));
                statement.setString(7,getItemStockUnit());
                statement.setString(8,jTaxTextField.getText().trim());
            }
            catch(Exception e)
            {
                System.out.println("Item.submitData() gave error ! "+e);
            }
        Connect.alert="Y";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }
     private void disableControls()
     {
        jNameTextField.setEnabled(false);
        jDescriptionTextArea.setEnabled(false);
        jPriceTextField.setEnabled(false);
        jTaxTextField.setEnabled(false);
        jTypeComboBox.setEnabled(false);
        jCategoryComboBox.setEnabled(false);
        jLocationComboBox.setEnabled(false);
        jStockUnitComboBox.setEnabled(false);
         
     }
     private void enableControls()
     {
        jNameTextField.setEnabled(true);
        jDescriptionTextArea.setEnabled(true);
        jPriceTextField.setEnabled(true);
        jTaxTextField.setEnabled(true);
        jTypeComboBox.setEnabled(true);
        jCategoryComboBox.setEnabled(true);
        jLocationComboBox.setEnabled(true);
        if(jTypeComboBox.getSelectedItem().toString().trim().equals("Stock"))
        {
            jStockUnitComboBox.setEnabled(true);
            resetStockUnit();
        }
         this.setTitle("::. New Item");
     }
     void resetCombo()
    {
        resetItemCategory();
        resetItemLocation();
        resetStockUnit();
        jTypeComboBox.setSelectedItem("-- Select --");
    }
     void reset()
    {
        jNameTextField.setText("");
        jDescriptionTextArea.setText("");
        jPriceTextField.setText("");
        jTaxTextField.setText("");
        resetCombo();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jAddressLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jCategoryComboBox;
    private javax.swing.JTextArea jDescriptionTextArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JComboBox jLocationComboBox;
    private javax.swing.JTextField jNameTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jPriceTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jStockUnitComboBox;
    private javax.swing.JTextField jTaxTextField;
    private javax.swing.JComboBox jTypeComboBox;
    // End of variables declaration//GEN-END:variables

}
